<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>toJSON 输出自定义属性</title>
</head>
<body>
<canvas id="c" width="200" height="200" style="border: 1px solid #ccc;"></canvas>
<button onclick="handleToJSON()">toJSON</button>

<script src="../../script/fabric.js"></script>
<script>
  let canvas = new fabric.Canvas('c')

  let rect = new fabric.Rect({
    width: 30,
    height: 30,
    top: 10,
    left: 10,
    my_id: 'rect01'
  })

  canvas.add(rect)

  function handleToJSON() {
    console.log(canvas.toJSON(['my_id']))
  }
</script>
</body>
</html>